package com.chance.cc.crawler.prod.command.job.domain.vm.bitauto.adhoc;

import com.alibaba.fastjson.JSON;
import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.CrawlerJob;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.HttpPage;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.meta.core.bean.CrawlerMetaConstant;
import com.chance.cc.crawler.meta.core.bean.job.CrawlerScheduleJob;
import com.chance.cc.crawler.prod.command.job.domain.vm.bitauto.BitAutoCommonCrawlerSchedulerJob;
import org.apache.commons.lang3.StringUtils;

import static com.chance.cc.crawler.development.scripts.allfeild.AICCommonField.Tag_Site_Info;

/**
 * @Author: ZhaoHhuan on 2021/9/3 16:58
 * @Email: 18638575967@163.com
 * @Description:
 *      易车视频根据
**/
public class BitAutoVideoArticleSimpleCrawlerSchedulerJob extends BitAutoCommonCrawlerSchedulerJob {
    private static final String crawler_level = "simple";

    public static void main(String[] args) {
        publishBitAutoCrawlerSchedulerJobInfo();
    }

    public static CrawlerJob publishBitAutoCrawlerSchedulerJobInfo(){
        CrawlerJob bitAutoScheduler = bitAutoScheduler();

        //发布定时任务
        CrawlerScheduleJob crawlerScheduleJob = new CrawlerScheduleJob();
        crawlerScheduleJob.setDomain(domain);
        crawlerScheduleJob.setCrawlerJob(JSON.toJSONString(bitAutoScheduler));
        crawlerScheduleJob.setJobType(CrawlerMetaConstant.ScheduleCrawlerJobType.crawler.enumVal());
        crawlerScheduleJob.setNote("易车新闻回溯七天评论采集任务");
        crawlerScheduleJob.setCrawlerKey(bitAutoScheduler.generateCrawlerKey());
        HttpPage httpPage = metaServiceCommand.addOrUpdateCrawlerScheduleJob(crawlerScheduleJob);
        System.out.println("发布任务：" + httpPage.getRawText());
        return bitAutoScheduler;
    }

    public static CrawlerJob bitAutoScheduler(){
        //视频采集
        CrawlerRequestRecord videoCrawler = doVideoCrawler();
        String site = videoCrawler.tagsCreator().bizTags().getCategoryTag().getKVTagStrVal("site");
        String redisRequestQueue = "crawler-bitauto-article-simple-queue";

        return CrawlerJob.builder()
                .triggerInfo(domain,
                        CrawlerMetaConstant.ScheduleJobTrigger_Cron,
                        System.currentTimeMillis(),
                        StringUtils.joinWith("-",site, "article",crawler_level,CrawlerMetaConstant.ScheduleJobTriggerJob_Realtime))
                .crawlerRequestQueue(CrawlerMetaConstant.redisRequestQueue(redisRequestQueue))
                .kafkaResultPipeline(null,kafkaTopciForTraceJob,null)
                .fileResultPipeline(null,"/data/chance_crawler_runner/logs/node/bitauto/bitauto_article_simple-20210903.log",false)
                .crawlerJobThreadNumber(30)
                .requestRecord(videoCrawler)
                .build();
    }


    public static CrawlerRequestRecord doVideoCrawler(){
        String site = "video";

        HttpConfig httpConfig = HttpConfig.me(domain);
        httpConfig.setHttpSite("video");
        CrawlerRequestRecord requestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .recordKey("https://v.yiche.com/")
                .httpUrl("https://v.yiche.com/")
                .releaseTime(System.currentTimeMillis())
                .httpConfig(httpConfig)
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.redisFilterKeyInfo(domain))
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*10,null))
                .needWashed(false)
                .needParsed(false)
                .proxy(proxy)
                .build();
        requestRecord.setSkipPipeline(true);
        requestRecord.setDownload(false);

        requestRecord.tagsCreator().bizTags().addDomain(domain);
        requestRecord.tagsCreator().bizTags().addSite(site);
        requestRecord.tagsCreator().bizTags().addSiteBiz(site);//脚本中指定的数据
        requestRecord.tagsCreator().bizTags().addCustomKV(Tag_Site_Info,"simple-20210804");
        return requestRecord;
    }
}
